package com.primb.bench.project.home.presenter;

import com.primb.bench.project.home.contract.HomeContract;
import com.primb.bench.project.home.model.HomeModelImpl;

import rx.Subscription;
import rx.subscriptions.CompositeSubscription;

/**
 * Created by Administrator on 2017/04/24
 */

public class HomePresenterImpl implements HomeContract.Presenter {
    private CompositeSubscription subscriptions;
    private HomeContract.View mView;
    private HomeModelImpl mModel;

    public HomePresenterImpl(HomeContract.View view) {
        this.mView = view;
        mModel = new HomeModelImpl();
        this.subscriptions = new CompositeSubscription();
    }

    @Override
    public void start() {
        mView.showLoading();
        Subscription subscribe = mModel.loadSpot(getUserId()).subscribe(mView::refreshSpot, throwable -> mView.showErrorMsg(throwable.getLocalizedMessage()), mView::hideLoading);
        subscriptions.add(subscribe);
    }

    @Override
    public void onRecycle() {
        subscriptions.clear();
    }

    @Override
    public String getUserId() {
        return "123";
    }
}